<div class="page-body">
    <div class="row">
        <div class="widget">
            <div class="widget-header
            <switch name="T_type">
            <case value="1">bg-magenta</case>
            <case value="2">bg-palegreen</case>
            <case value="3">bg-lightred</case>
            <case value="4">bg-blue</case>
            <case value="5">bg-blueberry</case>
            <case value="6">bg-gold</case>
            <default />bg-magenta
            </switch>
                                ">
            <span class="widget-caption">{$T_title|default=CONTROLLER_NAME}</span>
                                <!--Widget Buttons-->
        </div>
            <div class="widget-body">
                <div id="horizontal-form">
                    <form class="form-horizontal form_buy" role="form"
                          action="{:U('doDeposit')}"
                          method="post" enctype="multipart/form-data" onSubmit="return false;">
                        <div class="form-group">
                            <label for="card_id" class="col-sm-3 control-label no-padding-right">会员卡：</label>
                            <div class="col-sm-3">
                                <input type="text" autocomplete="off" class="form-control" id="card_id" name="card_id" value="" onkeydown="getCard()" >

                                <div id="card_info" style="display:none;">
                                    <span class="info"></span><br>
                                    购书折扣：<span class="discount_buy"></span><br>
                                    活动报名费折扣：<span class="discount_apply"></span><br>
                                    借阅可免运费次数：<span class="num_delivery"></span><br>
                                    活动报名费可免次数：<span class="num_activity"></span><br>
                                </div>
                            </div>
                        </div>
                        <hr>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">
                                充值类型：</label>
                            <div class="col-sm-3">
                                <select id="type_id" name="type_id" onchange="selType()">
                                    <option value="0">—— 请选择 ——</option>
                                    <volist name="type" id="v">
                                        <option value="{$v.type_id}">{$v.name}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right"></label>
                            <div class="col-sm-3">
                                <ul class="type_info">

                                </ul>
                            </div>
                        </div>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">总金额：</label>
                            <div class="col-sm-3">
                                <input type="number" id="money" name="money" class="form-control" value="" readonly="true" >
                            </div>
                            <div class="col-sm-6">
                                <span class="danger"></span>
                            </div>
                        </div>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">实收：</label>
                            <div class="col-sm-3">
                                <input type="number" id="money_real" name="money_real" class="form-control" value="" onkeyup="cal_zero()" onclick="cal_zero()">
                            </div>
                            <div class="col-sm-6">
                                <span class="danger"></span>
                            </div>
                        </div>

                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">找零：</label>
                            <div class="col-sm-3">
                                <input type="number" id="money_zero" name="money_zero" class="form-control" value="" >
                            </div>
                            <div class="col-sm-6">
                                <span class="danger"></span>
                            </div>
                        </div>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">支付方式：</label>
                            <div class="col-sm-3">
                                <select name="pay_way" id="pay_way">
                                </select>
                            </div>
                            <div class="col-sm-6">
                                <span class="danger"></span>
                            </div>
                        </div>
                        <div class="form-group  ">

                            <div class="col-sm-offset-3 col-sm-10">
                                <p class="label label-darkpink graded error_info"></p><br>
                                <input type="button" class="btn btn-primary" value="提交" onkeypress="FSubmit()" onclick="FSubmit()">
                                <input type="hidden" id="user_id" name="user_id" value="" >
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    //获取会员卡成功后回调
    function getsuccess(data){
        $("#user_id").val(data.data.user_id);
        $("#discount_buy").val(data.data.discount_buy);
        $("#card_info").show();
        $("#activity_id").focus();
    }
    //添加充值信息
    function selType() {
        var $type_id=$("#type_id").val();
        if($type_id==0){
            $(".type_info").html("");
            cal_all();
            return;
        }
            $.post("{:U('Card/type_search')}",{"type_id":$type_id},function(data){
                if(data.status=="error"){
                    alert(data.data);
                }else{
                        $str = '<li>'+
                                '<p>ID：<span class="type_id">'+data.data.type_id+'</span></p>'+
                                '<p class="活动名" title="'+data.data.name+'">名称：'+data.data.name+'</p>'+
                                '<p>延长月份：'+data.data.month+'</p>'+
                                '<p>可免借阅运费次数：<span class="">'+data.data.num_delivery+'</span></p>' +
                                '<p>可免报名活动费次数：<span class="">'+data.data.num_activity+'</span></p>'+
                                '<p>报名活动费折扣：'+data.data.discount_apply+'</p>' +
                                '<p>购书折扣：'+data.data.discount_buy+'</p>' +
                                '<p>价格：￥<span class="price">'+data.data.price+'</span></p>' +
                                '</li>';
                    $(".type_info").html($str);
                    cal_all();
                }
            },"json");
    }
    //计算总金额及活动折扣价等
    function cal_all(){
        var $m_total=$(".price").html();  //免活动费次数

        $("#money").val($m_total);
        cal_zero();
    }
    //计算找零
    function cal_zero(){
        var $m_total=$("#money").val();//实收
        if($m_total==""){
            $m_total=0;
        }
        var $m_real=$("#money_real").val();//实收
        if($m_real==""){
            $m_real=0;
        }
        var $m_zero=$m_real-$m_total;//找零
        $("#money_zero").val($m_zero.toFixed(2));
    }
    //提交
    function FSubmit(){
//        getCard_post();
//        cal_all();
        if(!confirm('确认操作?')){
            return;
        }
        if($("#user_id").val()==""){
            $(".error_info").html("请输入有效卡号");
            return;
        }
        if($("#type_id").val()==0){
            $(".error_info").html("请选择充值类型");
            return;
        }
        if($("#money_real").val()=="" || parseFloat($("#money_zero").val())<0){
            $(".error_info").html("请输入实收金额或找零错误");
            return;
        }

        $(".form_buy").attr("onSubmit","");
        $(".form_buy").submit();
        return true;
    }
</script>